﻿using AbstructFactory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using XF.Common;
using XF.Meeting.Api.Common;
using XF.Meeting.Common;
using XF.Meeting.Entity.CommonEntity;
using XF.Meeting.Entity.dbEntity;
using XF.Meeting.Entity.Query;

namespace XF.Meeting.Api.WebServices
{
    /// <summary>
    /// MeetWebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "XF.Meeting")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
     [System.Web.Script.Services.ScriptService]
    public class MeetWebService : System.Web.Services.WebService
    {
        public AbsFactoryTE abs = (AbsFactoryTE)AbsFactory.CreateInterface();
        [WebMethod]
        public string CreateResult(string strBTID, string strBOID, string bSuccess, int iProcInstID, string procURL, string strMessage)
        {
            if (bSuccess == "1")
            {
                var service = abs.CreateBPMInterface("审批创建结果", CommonIPHelper.GetIPAddress);
                if (string.IsNullOrEmpty(strBTID))
                {
                    strBTID = "strBTID为空";
                }
                if (iProcInstID==0)
                {
                    strBTID = "iProcInstID为0";
                }
                if (string.IsNullOrEmpty(procURL))
                {
                    strBTID = "procURL为空";
                }
            

                var result = service.CreateResult(strBTID, strBOID, iProcInstID, bSuccess, procURL, strMessage);
                return result.Result;
            }
            else
            {
                return "<success>成功</ success>";
            }

        }
        [WebMethod]
        public string Audit(string strBTID, string strBOID, int iProcInstID, string strStepName, string strApproverId, string eAction, string strComment, System.DateTime dtTime)
        {
            if (string.IsNullOrWhiteSpace(strBTID))
            {
                return "<error>strBTID为空</error>";
            }
            if (string.IsNullOrWhiteSpace(strBOID))
            {
                return "<error>strBOID为空</error>";
            }
            if (iProcInstID == 0)
            {
                return "<error>iProcInstID为0</error>";
            }
            if (string.IsNullOrWhiteSpace(strStepName))
            {
                return "<error>strStepName为空</error>";
            }
            if (string.IsNullOrWhiteSpace(strApproverId))
            {
                return "<error>strApproverId为空</error>";
            }
            if (string.IsNullOrWhiteSpace(eAction))
            {
                return "<error>eAction为空</error>";
            }
            if (string.IsNullOrWhiteSpace(strComment))
            {
                return "<error>strComment为空</error>";
            }
            if (dtTime == null)
            {
                return "<error>dtTime为空</error>";
            }
            var service = abs.CreateBPMInterface("流程审批过程中", CommonIPHelper.GetIPAddress);
            var result = service.Audit(strBTID, strBOID, iProcInstID, strStepName, strApproverId, eAction, strComment, dtTime).Result;
            return result;
        }

        [WebMethod]
        public string ApproveClose(string strBTID, string strBOID, int iProcInstID, string eProcessInstanceResult, string strComment, DateTime dtTime)
        {
            var service = abs.CreateBPMInterface("审批结束", CommonIPHelper.GetIPAddress);
            if (eProcessInstanceResult=="1"&& strBTID== "DY_MeetManage_Reserve")
            {
                var wx = new WeChatHelper();

                wx.SendWxMssage(new CRoomPadQuery() {  strBOID =strBOID,type=2},false);
            }
            var bResult = service.ApproveClose( strBTID,  strBOID,  iProcInstID,  eProcessInstanceResult,  strComment,  dtTime).Result;
            return "<success>成功<success>";
        }


    }
}
